<template>
  <el-dialog :visible="dialogVisible" v-if="dialogVisible" width="35%" :before-close="closeForm">
    <el-form :model="form" :rules="rules" :status-icon="true" ref="form" label-width="80px">
      <el-row :gutter="0">
        <el-col :span="24">
          <el-form-item
            v-if="form.orderReceipt.receipt_msg.receipt"
            label="收货人"
            prop="orderReceipt.receipt_msg.receipt.kr"
          >
            <el-input
              v-if="form.orderReceipt.receipt_msg.receipt.kr"
              placeholder="请输入收货人"
              v-model="form.orderReceipt.receipt_msg.receipt.kr"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="PCC" prop="orderReceipt.receipt_msg.PCC">
            <el-input
              v-if="form.orderReceipt.receipt_msg"
              placeholder="请输入PCC"
              v-model="form.orderReceipt.receipt_msg.PCC"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="电话号码" prop="orderReceipt.receipt_msg.Tel">
            <el-input
              v-if="form.orderReceipt.receipt_msg"
              placeholder="请输入电话号码"
              v-model="form.orderReceipt.receipt_msg.Tel"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button size="small" type="primary" @click="handleSubmit"
      ><i class="el-icon-circle-plus-outline"></i> 保存
      </el-button>
      <el-button size="small" @click="closeForm"><i class="el-icon-circle-close"></i> 取消 </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "fillPccModule",
  props: {
    editData: {
      type: Object,
      default: () => ({})
    },
    dialogTitle: {
      type: String,
      default: ""
    },
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {},
      rules: {
        "orderReceipt.receipt_msg.receipt.kr": [
          {
            required: true,
            message: "请输入收货人",
            trigger: ["blur", "change"]
          }
        ],
        "orderReceipt.receipt_msg.PCC": [
          {
            required: true,
            message: "请输入PCC",
            trigger: ["blur", "change"]
          }
        ],
        "orderReceipt.receipt_msg.Tel": [
          {
            required: true,
            message: "请输入电话",
            trigger: ["blur", "change"]
          }
        ]
      }
    };
  },
  watch: {
    editData: {
      handler(val) {
        this.form = JSON.parse(JSON.stringify(val));
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit("submit", {
            id: this.form.storage_order_id,
            name: this.form.orderReceipt.receipt_msg.receipt.kr,
            phone: this.form.orderReceipt.receipt_msg.Tel,
            pcc: this.form.orderReceipt.receipt_msg.PCC
          });
        }
      });
    },
    closeForm() {
      this.$emit("closeForm");
      if (this.$refs["form"] !== undefined) {
        this.$refs["form"].resetFields();
      }
    }
  }
};
</script>

<style scoped lang="scss"></style>
